package com.goodedeeds.domain.resource;

import com.youtills.resource.*;
import com.youtills.action.ActionContext;

import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: rchiluve
 * Date: 2/23/14
 * Time: 7:48 PM
 * To change this template use File | Settings | File Templates.
 */
public class Project extends BaseResource implements Resource {

    public static final long RT_PROJECT = 100002;
    public static final long RL_RESOURCE_PROJECT = 100002;

    private final ResourceAttributeValue<String> projectName;
    private final ResourceAttributeValue<String> projectDescription;
    private final ResourceAttributeValue<Integer> projectStatus;
    private final ResourceAttributeValue<String> projectKey;
    private final ResourceAttributeValue<Date> projectStartDate;
    private final ResourceAttributeValue<Date> projectEndDate;
    private final ResourceAttributeValue<Double> goalAmount;
    private final ResourceRelationship<Resource, Project> resourceProjects;

    public void addResourceId(long resourceType, long resourceId) {
            resourceProjects.addTargetResourceId(resourceType, resourceId, null);
    }

    public List<School> getSchools(ActionContext ac) {
        Long[] schoolIds = resourceProjects.getTargetResourceIds();
        return ResourceManager.instance.getResourcesBulk(ac, School.class, schoolIds);

    }

    public Project() {
        super(RT_PROJECT);
        this.projectName = new ResourceAttributeValue<String>(this, GoodeDeedsAttribute.projectName);
        this.projectDescription = new ResourceAttributeValue<String>(this, GoodeDeedsAttribute.projectDescription);
        this.projectStatus = new ResourceAttributeValue<Integer>(this, GoodeDeedsAttribute.projectStatus);
        this.projectKey = new ResourceAttributeValue<String>(this, GoodeDeedsAttribute.projectKey);
        this.projectStartDate = new ResourceAttributeValue<Date>(this, GoodeDeedsAttribute.projectStartDate);
        this.projectEndDate = new ResourceAttributeValue<Date>(this, GoodeDeedsAttribute.projectEndDate);
        this.goalAmount = new ResourceAttributeValue<Double>(this, GoodeDeedsAttribute.projectGoalAmount);

        resourceProjects = new ResourceRelationship<>(ResourceRelationship.SourceLocation.right, null, this, GoodeDeedsAttribute.resource_project);
    }

    public Long getProjectId() {
        return getResourceId();
    }

    public String getProjectName() {
        return projectName.getValue();
    }

    public String getProjectDescription() {
        return projectDescription.getValue();
    }

    public int getProjectStatus() {
        return projectStatus.getValue();
    }

    public String getProjectKey() {
        return projectKey.getValue();
    }

    public void setProjectName(String projectName) {
        this.projectName.setValue(projectName);
    }

    public void setProjectDescription(String projectDescription) {
        this.projectDescription.setValue(projectDescription);
    }

    public void setProjectStatus(int projectStatus) {
        this.projectStatus.setValue(projectStatus);
    }

    public void setProjectKey(String projectKey) {
        this.projectKey.setValue(projectKey);
    }

    public Date getProjectStartDate() {
        return projectStartDate.getValue();
    }

    public void setProjectStartDate(Date projectStartDate) {
        this.projectStartDate.setValue(projectStartDate);
    }

    public Date getProjectEndDate() {
        return projectEndDate.getValue();
    }

    public void setProjectEndDate(Date projectEndDate) {
        this.projectEndDate.setValue(projectEndDate);
    }

    public Double getGoalAmount() {
        return goalAmount.getValue();
    }

    public void setGoalAmount(Double goalAmount) {
        this.goalAmount.setValue(goalAmount);
    }

    @Override
    protected String getTableName() {
        return "ged__project";
    }

    @Override
    protected String getResourceIdColumn() {
        return "project_id";
    }

}